package org.shenba.springbible.controllers;

import java.util.ArrayList;

import org.shenba.springbible.models.Bible;
import org.shenba.springbible.services.KJVService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/kjv")
public class KJVController {
	
	private KJVService kjvService;
	
	@RequestMapping(value = "/home.do")
	public String loadHome(Model model) {
		model.addAttribute(kjvService.getBookList());
		return "home";
	}
	
	@RequestMapping(value = "/getChapterList.do")
	public @ResponseBody ArrayList<String> getChapterList(@ModelAttribute Bible bible) {
		return kjvService.getChapterList(bible);
	}
	
	@RequestMapping(value = "/getVerseList.do")
	public @ResponseBody ArrayList<String> getVerseList(@ModelAttribute Bible bible) {
		return kjvService.getVerseList(bible);
	}
	
	@RequestMapping(value = "/getVerse.do")
	public @ResponseBody Bible getVerse(@ModelAttribute Bible bible) {
		bible.setText(kjvService.getSelectedVerse(bible));
		return bible;
	}
	
	@ModelAttribute("bible")
	public Bible getBible() {
		return new Bible();
	}
	
	@Autowired
	public void setKJVService(KJVService kjvService) {
		this.kjvService = kjvService;
	}
	
}
